package com.eastcom.providor.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.eastcom.bm.atom.Atom_PPMDefine;
import com.eastcom.client.PPMdefineInfo;
import com.eastcom.providor.dao.IPPMDefineDao;
import com.eastcom.providor.service.BaseService;
import com.eastcom.providor.service.IPPMDefineService;

public class PPMDefineService extends BaseService  implements IPPMDefineService {

	private IPPMDefineDao ppmDefineDao;

	public void setPpmDefineDao(IPPMDefineDao ppmDefineDao) {
		this.ppmDefineDao = ppmDefineDao;
	}
	
	public List<Atom_PPMDefine> selectPPMDefineByParams(String business, String reportName) {
        try{
			return ppmDefineDao.selectPPMDefineByParams(business, reportName);
		}
		catch(Exception e){
			log.error("PPMDefineService selectPPMDefineByParams error", e);
		}
		
		return null;
	}
	
	public List selectPPMdefineLastUpLoadInfoByParams(String business,String reportName, Date startDate, Date endDate) {
		try{
			
			return ppmDefineDao.selectPPMdefineInfoByParams(business, reportName, startDate, endDate);
		}
		catch(Exception e){
			log.error("PPMDefineService selectPPMdefineLastUpLoadInfoByParams error", e);
		}
		
		return null;
	}

	public List<PPMdefineInfo> selectPPMdefineHistoryInfoByParams(String business, String reportName, Date startDate, Date endDate) throws Exception {
		try{
			return ppmDefineDao.selectPPMdefineHistoryInfoByParams(business, reportName, startDate, endDate);
		}
		catch(Exception e){
			log.error("PPMDefineService selectPPMdefineHistoryInfoByParams error", e);
		}
		
		return null;
	}
	

	public Map selectPPMdefineLastUpLoadInfoMapByParams(String business, String reportName, Date startDate, Date endDate)
	{
		List<PPMdefineInfo> list=new ArrayList<PPMdefineInfo>();
		try{
			
			list= ppmDefineDao.selectPPMdefineInfoByParams(business, reportName, startDate, endDate);
		}
		catch(Exception e){
			log.error("PPMDefineService selectPPMdefineLastUpLoadInfoByParams error", e);
		}
		Map<String,List<PPMdefineInfo>> map=new HashMap<String,List<PPMdefineInfo>>();
		for(PPMdefineInfo ppm:list)
		{
			String bsName=ppm.getBusiness();
			if(map.containsKey(bsName))//如果包含追加
			{
				List<PPMdefineInfo> mapList=map.get(bsName);
				mapList.add(ppm);
				map.put(bsName, mapList);
			} else if (bsName == null) {
			}
			else {
				List<PPMdefineInfo> mapList = new ArrayList<PPMdefineInfo>();
				mapList.add(ppm);
				map.put(bsName, mapList);
			}
		}
		/*List result=new ArrayList();
		result.add(map.keySet());
		result.add(map);*/
		return map;
	}

}
